<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('集中器设备数据列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>集中器ID：</label>
                            <input type="text" name="concentratorId"/>
                        </li>
                        <li>
                            <label>集中器型号：</label>
                            <select id="concentratorType" name="typeId">
                                <option value="0">所有</option>
                                <option th:each="concentrator : ${concentratorList}" th:text="${concentrator['typeName']}" th:value="${concentrator['typeId']}" th:field="*{type.typeId}"></option>
                            </select>
                        </li>
                        <li>
                            <label>安装标识：</label>
                            <select name="status" th:with="type=${@dict.getType('equipment_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <li class="select-time">
                            <label>安装时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginInstallTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endInstallTime]"/>
                        </li>
                        <li>
                            <label>安装人：</label>
                            <input type="text" name="installUser"/>
                        </li>

                        <li>
                            <label>Sim卡号：</label>
                            <input type="text" name="concentratorSim"/>
                        </li>
                        <li>
                            <label>运营商：</label>
                            <input type="text" name="concentratorYys"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="add()" shiro:hasPermission="module:concentrator:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="module:concentrator:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="module:concentrator:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="module:concentrator:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-warning" onclick="$.table.importExcel()" shiro:hasPermission="module:concentrator:import">
                <i class="fa fa-download"></i> 导入
            </a>
            <a class="btn btn-warning multiple disabled" onclick="initialize()" shiro:hasPermission="module:concentrator:initialize">
                <i class="fa fa-download"></i> 采集器初始化
            </a>
            <a class="btn btn-warning multiple disabled" onclick="heart()" shiro:hasPermission="module:concentrator:heart">
                <i class="fa fa-download"></i> 设置心跳时间
            </a>
            <a class="btn btn-warning multiple disabled" onclick="settime()" shiro:hasPermission="module:concentrator:settime">
                <i class="fa fa-download"></i> 设置抄表时间
            </a>
            <a class="btn btn-warning single disabled" onclick="aperture()" shiro:hasPermission="module:concentrator:aperture">
                <i class="fa fa-download"></i> 设置阀门开度
            </a>
            <br/>
            <a class="btn btn-warning single disabled" onclick="select()" shiro:hasPermission="module:concentrator:check">
                <i class="fa fa-download"></i> 获取登记设备
            </a>
            <a class="btn btn-warning single disabled" onclick="check()" shiro:hasPermission="module:concentrator:check">
                <i class="fa fa-download"></i> 设备批量采集
            </a>
            <a class="btn btn-warning multiple disabled" onclick="change()" shiro:hasPermission="module:concentrator:change">
                <i class="fa fa-download"></i> 修改服务器地址
            </a>
            <a class="btn btn-warning multiple disabled" onclick="correct()" shiro:hasPermission="module:concentrator:correct">
                <i class="fa fa-download"></i> 校准采集器时间
            </a>
            <a class="btn btn-warning multiple disabled" onclick="collect()" shiro:hasPermission="module:concentrator:collect">
                <i class="fa fa-download"></i> 查询采集器时间
            </a>
            <a class="btn btn-warning single disabled" onclick="dispel()" shiro:hasPermission="module:concentrator:dispel">
                <i class="fa fa-download"></i> 消除MBUS过载警示
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('module:concentrator:edit')}]];
    var removeFlag = [[${@permission.hasPermi('module:concentrator:remove')}]];
    var prefix = ctx + "module/concentrator/data";
    var datas = [[${@dict.getType('equipment_status')}]];

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            importUrl: prefix + "/importData",
            exportUrl: prefix + "/export",
            queryParams: queryParams,
            importTemplateUrl: prefix + "/importTemplate",
            modalName: "集中器设备数据",
            columns: [{
                checkbox: true
            },
                {
                    field: 'concentratorId',
                    title: '集中器ID'
                },
                {
                    field: 'concentratorType.typeName',
                    title: '集中器型号'
                },
                {
                    field: 'status',
                    title: '设备状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'installTime',
                    title: '安装时间'
                },
                {
                    field: 'installAddress',
                    title: '安装地址'
                },
                {
                    field: 'installPosition',
                    title: '安装位置'
                },
                {
                    field: 'installUser',
                    title: '安装人'
                },
                {
                    field: 'factory.factoryName',
                    title: '厂商名称'
                },
                {
                    field: 'factory.factoryCode',
                    title: '厂商代码'
                },
                {
                    field: 'concentratorSim',
                    title: 'Sim卡号'
                },
                {
                    field: 'concentratorYys',
                    title: '运营商'
                },
                {
                    field: 'concentratorZfdq',
                    title: '资费到期'
                },
                {
                    field: 'concentratorZfsm',
                    title: '资费说明'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.concentratorId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.concentratorId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-default btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="authValve(\'' + row.concentratorId + '\')"><i class="fa fa-valve"></i>分配阀门</a> ');
                        actions.push('<a class="btn btn-default btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="authMeter(\'' + row.concentratorId + '\')"><i class="fa fa-calorimeter"></i>分配热表</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.typeId = $("#concentratorType").val();
        return search;
    }

    function add() {
        var concentratorType = $("#concentratorType option:selected").val();
        $.operate.add(concentratorType);
    }

    /* 集中器管理-分配热表 */
    function authMeter(concentratorId) {
        var url = prefix + '/authMeter/' + concentratorId;
        $.modal.openTab("分配热表", url);
    }

    /* 集中器管理-分配阀门 */
    function authValve(concentratorId) {
        var url = prefix + '/authValve/' + concentratorId;
        $.modal.openTab("分配阀门", url);
    }

    /* 采集器初始化 */
    function initialize(){
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var rows = $.table.selectFirstColumns();
        $.modal.confirm("采集器初始化将会导致关联的设备数据清空，请谨慎操作？", function() {
            $.operate.post(prefix + "/initialize", { "concentratorIds": rows.join() });
        })
    }

    /* 设置采集器心跳时间 */
    function heart(){
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var rows = $.table.selectFirstColumns();
        var url = prefix + '/heart/' + rows.join();
        $.modal.open("设置采集器心跳时间", url, '800', '300');
    }

    /* 设置采集器离线抄表时间 */
    function settime(){
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var rows = $.table.selectFirstColumns();
        var url = prefix + '/settime/' + rows.join();
        $.modal.open("设置采集器离线抄表时间", url, '800', '300');
    }

    /* 设置阀门开度 */
    function aperture(){
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var rows = $.table.selectFirstColumns();
        var url = prefix + '/aperture/' + rows.join();
        $.modal.open("设置阀门开度", url, '800', '300');
    }

    /* 获取登记设备 */
    function select(){
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var rows = $.table.selectFirstColumns();
        $.operate.post(prefix + "/select", { "concentratorIds": rows.join() });
    }

    /* 批量读取设备数据 */
    function check(){
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var rows = $.table.selectFirstColumns();
        $.operate.post(prefix + "/check", { "concentratorIds": rows.join() });
    }

    /* 设置服务器地址 */
    function change(){
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var rows = $.table.selectFirstColumns();
        var url = prefix + '/change/' + rows.join();
        $.modal.open("设置服务器地址", url, '800', '300');
    }

    /* 查询采集器时间 */
    function collect(){
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var rows = $.table.selectFirstColumns();
        $.operate.post(prefix + "/collect", { "concentratorIds": rows.join() });
    }

    /* 校准采集器时间 */
    function correct(){
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var rows = $.table.selectFirstColumns();
        $.modal.confirm("确认要校准选中的采集器时间吗？", function() {
            $.operate.post(prefix + "/correct", { "concentratorIds": rows.join() });
        })
    }

    /* 消除mbus告警 */
    function dispel(){
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var rows = $.table.selectFirstColumns();
        $.modal.confirm("确认要消除此采集器的MBUS告警提示？", function() {
            $.operate.post(prefix + "/dispel", { "concentratorIds": rows.join() });
        })
    }
</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果集中器信息已经存在，更新这条数据。"> 是否更新已经存在的集中器信息
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>